import { connectRouter, routerMiddleware } from 'connected-react-router';
import { createStore, combineReducers, applyMiddleware } from 'redux';
import thunk from 'redux-thunk';
import rootReducers from 'reducers';

export default function configureStore(initialState, history) {
  const reducers = combineReducers({
    router: connectRouter(history),
    ...rootReducers,
  });

  const middlewares = applyMiddleware(
    routerMiddleware(history),
    thunk,
  );

  const store = createStore(reducers, initialState, middlewares);

  return store;
}
